package com.googlecode.messwertepi.input;

import com.google.inject.Inject;
import com.googlecode.messwertepi.gui.MainWindow;
import com.googlecode.messwertepi.model.DataModel;
import jcurses.system.InputChar;
import jcurses.system.Toolkit;

import java.util.Random;


/**
 * Created by eike on 05.07.14.
 */
public class KeyboardInputReader implements Runnable {

    final private DataModel dataModel;
    final private MainWindow window;

    @Inject
    public KeyboardInputReader(DataModel dataModel, MainWindow window) {
        this.dataModel = dataModel;
        this.window = window;

    }

    @Override
    public void run() {
        while (true) {
            try {
                InputChar in = Toolkit.readCharacter();
                switch (in.getCharacter()) {
                    case 'q':
                        dataModel.setInput(getRandomString(32));
                        break;

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private String getRandomString(int length)
    {
        String result = "";
        Random rand = new Random();
        for (int i = 0; i < length; i++) {
            result += (char)(rand.nextInt(26) + 'a');
        }

        return result;
    }
}